import java.sql.*;
public class TestH2 {
    public static void main(String[] a) throws Exception {
		Connection conn= DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test", "sa", "");
		Statement stmt;
		Class.forName("org.h2.Driver");
	    // conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		Statement stmt1 = conn.createStatement() ;
	        // add application code here
		// Execute the query
		ResultSet rs = stmt1.executeQuery( "SELECT table_name FROM information_schema.tables" ) ;
		
		// Loop through the result set
		while( rs.next() ) System.out.println( rs.getString(1) );
		
		// Close the result set, statement and the connection
		rs.close() ;
		stmt1.execute("CREATE TABLE IF NOT EXISTS CUSTOMERS(ID INT PRIMARY KEY,NAME VARCHAR(255))");
		stmt1.execute("CREATE USER IF NOT EXISTS TestDB PASSWORD 'abcd'");
		stmt1.execute("GRANT ALL ON CUSTOMERS TO TestDB");
		stmt1.close() ;
	        conn.close();
		
		//        conn = DriverManager.getConnection("jdbc:h2:~/test", "TestDB", "abcd");
	        conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test", "TestDB", "abcd");
	
		stmt1 = conn.createStatement() ;
		stmt1.execute("INSERT INTO CUSTOMERS VALUES ('1234567890', 'Rajiv Ramnath')");
    }
}
